<?php

/**
 * Created by PhpStorm
 * USER MingTingLiang   QQ 915802070
 * Date 2020-12-17-017   21:32
 */
class  State
{
    public $root;
    public $modules;

    public function __construct()
    {
        $this->root = new class() {

        };
        $this->modules = new class() {

        };
    }

    public function setState(...$states)
    {
        $prop = $states[0];
        if (count($states) == 3) { //模块存储
            if (!isset($this->modules->$prop)) {
                $this->modules->$prop = (object)[$states[1] => $states[2],
                ];
            } else {
                $key = $states[1];
                $this->modules->$prop->$key = $states[2];
            }
        } else if (count($states) == 2) { //根存储
            $this->root->$prop = $states[1];
        }
    }

}